/*
 * @Description: 
 * @Author: Aroma
 * @Date: 2024-09-18 15:47:36
 * @LastEditors: Aroma
 * @LastEditTime: 2024-09-18 17:32:35
 * @别瞎看: 你个无脑牛马
 */
import java.util.Scanner;
public class StudentManagement{
    private Student[] stus;
    private int counter;
    private Scanner in;

    public StudentManagement(){
        stus=new Student[100];
        in =new Scanner(System.in);
    }

    public StudentManagement(int size){
        stus=new Student[size];
        in=new Scanner(System.in);
    }

    public void prompt(){
        System.out.println("********************");
        System.out.println("*Student Management*");
        System.out.println("********************");
        System.out.println("*1)Add");
        System.out.println("*2)Delete");
        System.out.println("*3)Uplate");
        System.out.println("*4)Select");
        System.out.println("*0)Quit");
        System.out.println("********************");
        System.out.println("Please choose your operate:");
    }

    private int findStudent(){
        int index=-1;
        String name;
        System.out.println("Please input name:");
        name=in.next();
        for(int i=0;i<stus.length;i++){
            if(stus[i].equals(name)){
                index=i;
                break;
            }
        }
        return index;
    }

    private void addStudent(){
        String name;
        int age;
        String gender;
        Student s;
        if(counter>=stus.length){
            System.out.println("Add failure,too many student!");
            return;
        }
        System.out.println("Please input name:");
        name=in.next();
        System.out.println("Please input age:");
        age=in.nextInt();
        System.out.println("Please input gender:");
        gender=in.next();
        s=new Student(name,age,gender);
        stus[counter]=s;
        counter++;
        System.out.println("Add student success!");
    }

    public void deleteStudent(){
        String name;
        boolean found=false;
        System.out.println("Please input name:");
        name=in.next();
        for(int i=0;i<counter;i++){
            if(stus[i].getName().equals(name)){
                for(int j=i;j<counter-1;j++){
                    stus[j]=stus[j+1];
                }
                counter--;
                found=true;
                break;
            }
        }
        if(found){
            System.out.println("Delete student success!");
        }else{
            System.out.println("Student not found");
        }
    }
       
    

    public void updateStudent(){
        String name;
        String newname;
        int age;
        int newage;
        String gender;
        String newgender;
        boolean found=false;
        System.out.println("Please input name:");
        name=in.next();
        System.out.println("Please input new name:");
        newname=in.next();
        System.out.println("Please input new age:");
        newage=in.nextInt();
        System.out.println("Please input new gender:");
        newgender=in.next();
        for(int i=0;i<counter;i++){
            if(stus[i].getName().equals(name)){
                stus[i]=new Student(newname,newage,newgender);
                found=true;
                break;
            }
        }
        if(found){
            System.out.println("Update student success!");
        }else{
            System.out.println("Student not found");
        }
    }

    public void selectStudent(){
        String name;
        Student s;
        boolean found=false;
        System.out.println("Please input name:");
        name=in.next();
        System.out.println(name);
        System.out.println(stus.toString());
        System.out.println(counter);
        for(int j=0;j<counter;j++){
            System.out.println("stus[j].getname()"+stus[j].getName());
        }
        for(int i=0;i<counter;i++){
            if(stus[i].getName().equals(name)){
                System.out.println("Found student:"+stus[i].getName()+", age: " + stus[i].getAge() + ", gender: " + stus[i].getGender());
                found=true;
                break;
            }
        }
        if(!found){
            System.out.println("Student not found!");
        } 
    }

    public static void main(String[] agrs){
        StudentManagement sm=new StudentManagement();
        int option=-1;
        Loop:while(true){
            sm.prompt();
            option=sm.in.nextInt();
            if(option<0||option>4)
                continue;
            switch(option){
                case 1:
                    sm.addStudent();
                    break;
                case 2:
                    sm.deleteStudent();
                    break;
                case 3:
                    sm.updateStudent();
                    break;
                case 4:
                    sm.selectStudent();
                    break;
                case 0:
                    break Loop;
            }
        }
        System.out.println("游戏结果,byebye");
    }
}